package com.beadhouse.common.util;

import java.util.regex.Pattern;

import com.beadhouse.common.exeption.BeadHouseException;



/**
 * 参数验证
 * 
 * @author Administrator
 *
 */
public class AssertUtil {

	static public void assertMatch(String message, String target, String regex) {
		Pattern pattern = Pattern.compile(regex);
		if (!pattern.matcher(target).matches()) {
			throw new BeadHouseException(message);
		}
	}

	static public void assertBetween(String message, String s, int min, int max) {
		if (s.length() < min || s.length() > max) {
			throw new BeadHouseException(message + "必须大于" + min + "位且小于" + max + "位");
		}
	}

	static public String $(String message, String s) {
		return assertNotBlank(message, s);
	}

	static public String assertNotBlank(String message, String s) {
		if (s == null || (s = s.trim()).length() == 0) {
			throw new BeadHouseException(message + "不能为空");
		}
		return s;
	}

	static public void assertTrue(String message, boolean b) {
		if (!b) {
			throw new BeadHouseException(message);
		}
	}

	static public void assertFalse(String message, boolean b) {
		if (b) {
			throw new BeadHouseException(message);
		}
	}
	static public void assert32bit(String message,String s) {
		if(s.length()>32) {
			throw new BeadHouseException(message+"不存在");
		}
	}
	
}
